﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using AutoMapper;
using PublishNews.Entities;
using PublishNews.Models;
using PublishNews.Repositories;

namespace PublishNews.Controllers
{
    public class LocationApiController : BaseApiController<Location, LocationModel>
    {
        public LocationApiController(ILocationRepository repository)
            : base(repository)
        {

        }

        public override IHttpActionResult Get()
        {
            var entities = Repository.DbSet().OrderByDescending(x => x.UpdatedDate).ThenByDescending(x => x.CreatedDate);
            var model = Mapper.Map<IEnumerable<LocationModel>>(entities);
            model = model.OrderBy(x => x.Name);
            return Ok(model);
        }
    }
}
